<!DOCTYPE html><!--原生JS-->
<html>
<head>
  <meta charset="UTF-8">
  <style>
    .modal {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      z-index: 1000;
      display: none;
    }

    .modal.active {
      display: block;
    }

    .modal-backdrop {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: linear-gradient(45deg, rgba(255, 192, 203, 0.3), rgba(173, 216, 230, 0.3));
      cursor: pointer;
    }

    .modal-dialog {
      position: relative;
      width: auto;
      max-width: 280px;
      margin: 100px auto;
    }

    .modal-content {
      background-color: #fff;
      border-radius: 8px;
      box-shadow: 0 0 12px rgba(0, 0, 0, 0.15);
      padding: 16px;
      display: flex;
      flex-direction: column;
      align-items: center;
    }

    .loading-image {
      height: 150px;
      display: block;
      margin: 0 auto 12px;
    }

    .loading-text {
      text-align: center;
      margin: 0 0 15px 0;
    }

    .modal-footer {
      margin-top: 15px;
    }
  </style>
</head>
<body>
<button id="openModal">显示模态框</button>

<div id="myModal" class="modal">
  <div class="modal-backdrop" id="modalBackdrop"></div>
  <div class="modal-dialog">
    <div class="modal-content">
      <p class="loading-text">我是原生JS做的模态框</p>
      <img src="../resources/images/whitecat_3.gif" class="loading-image">
      <div class="modal-footer">
        <button id="closeModal">关闭</button>
      </div>
    </div>
  </div>
</div>

<script>
  // 获取DOM元素
  var modal = document.getElementById('myModal');
  var openBtn = document.getElementById('openModal');
  var closeBtn = document.getElementById('closeModal');
  var backdrop = document.getElementById('modalBackdrop');

  // 打开模态框
  openBtn.onclick = function() {
    modal.classList.add('active');
    document.body.style.overflow = 'hidden';
  }

  // 关闭模态框的函数
  function closeModal() {
    modal.classList.remove('active');
    document.body.style.overflow = '';
  }

  // 点击关闭按钮关闭
  closeBtn.onclick = closeModal;

  // 点击背景关闭
  backdrop.onclick = closeModal;

  // 按ESC键关闭
  document.onkeydown = function(event) {
    if (event.key === 'Escape' && modal.classList.contains('active')) {
      closeModal();
    }
  }
</script>
</body>
</html>
